﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Mobile.Mvc;
using MultiPanelTest.Data;

namespace MultiPanelTest.Login
{
    public partial class LoginView : ViewControl, IView<LoginModel>
    {
        public LoginView()
        {
            InitializeComponent();
        }       

        protected override void OnUpdateView(string key)
        {
            // Controller requested to update the view
            if (key == "Status")
            {
                // Update status label
                this.lblStatus.Text = this.ViewData["Status"].ToString();
            }
        }
       
        public new void Show()
        {
            this.Visible = true;

            Form parent = this.Parent as Form;
            parent.Menu.MenuItems[0].Text = "Cancel";
            parent.Menu.MenuItems[1].Text = "Login";

            // Hookup the right menu click
            parent.Menu.MenuItems[1].Click += new EventHandler(OnLogin);
            parent.Menu.MenuItems[0].Click += new EventHandler(Cancel_Click);
        }

        public new void Hide()
        {
            this.Visible = false;

            Form parent = this.Parent as Form;
            // Hookup menu clicks
            parent.Menu.MenuItems[1].Click -= new EventHandler(OnLogin);
            parent.Menu.MenuItems[0].Click -= new EventHandler(Cancel_Click);
        }

        private void OnLogin(object sender, EventArgs e)
        {
            // Assign the values
            this.Model.User = txtUser.Text;
            this.Model.Password = txtPassword.Text;
            // Notify the Controller
            this.OnViewStateChanged("Login");
        }

       

        private void Cancel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        #region IView<LoginModel> Members

        public new ViewDataDictionary<LoginModel> ViewData
        {
            get;
            set;
        }

        public new LoginModel Model
        {
            get;
            set;

        }

        #endregion
    }
}
